<template>
  <div class="app-container">
    <p>1、工程信息</p>
    <table cellpadding="0" cellspacing="0">
      <tr>
        <th style="width: 20%;">建设单位</th>
        <td style="width: 30%;"></td>
        <th style="width: 20%;">合同编号</th>
        <td style="width: 30%;"></td>
      </tr>
      <tr>
        <th>发包单位</th>
        <td></td>
        <th>合同金额</th>
        <td></td>
      </tr>
      <tr>
        <th>工程名称</th>
        <td></td>
        <th>未税金额</th>
        <td></td>
      </tr>
      <tr>
        <th>工程地点</th>
        <td></td>
        <th>入账金额</th>
        <td></td>
      </tr>
      <tr>
        <th>工程期限</th>
        <td></td>
        <th>支出金额</th>
        <td></td>
      </tr>
      <tr>
        <th>工程性质</th>
        <td></td>
        <th>盈余金额</th>
        <td></td>
      </tr>
    </table>
    <p>2、工事清单</p>
    <table cellpadding="0" cellspacing="0">
      <tr>
        <th style="width: 5%;">序号</th>
        <th style="width: 5%;">属性</th>
        <th style="width: 25%;">工程名称</th>
        <th style="width: 20%;">合同金额</th>
        <th style="width: 5%;">税率</th>
        <th style="width: 20%;">未税金额</th>
        <th style="width: 20%;">入账金额</th>
      </tr>
    </table>
    <p>3、成本分析</p>
    <table cellpadding="0" cellspacing="0">
      <tr>
        <th style="width: 5%;">代码</th>
        <th style="width: 15%;">投标预算</th>
        <th style="width: 10%;">比率</th>
        <th style="width: 15%;">实施预算</th>
        <th style="width: 10%;">比率</th>
        <th style="width: 15%;">实际金额</th>
        <th style="width: 10%;">比率</th>
        <th style="width: 20%;">支出金额</th>
      </tr>
      <tr>
        <td>合计</td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td>净利</td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
      </tr>
      <tr>
        <td>毛利</td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
      </tr>
    </table>
    <p>4、调整历程</p>
    <table cellpadding="0" cellspacing="0">
      <tr>
        <th style="width: 5%;">序号</th>
        <th style="width: 20%;">合同金额</th>
        <th style="width: 20%;">利润额</th>
        <th style="width: 10%;">利率</th>
        <th style="width: 15%;">作成日期</th>
        <th style="width: 30%;">备注</th>
      </tr>
    </table>
    <p>5、会签流程</p>
    <table cellpadding="0" cellspacing="0">
      <tr>
        <th style="width: 10%;">职务</th>
        <th style="width: 18%;">总经理</th>
        <th style="width: 18%;">财务</th>
        <th style="width: 18%;">采购</th>
        <th style="width: 18%;">销售部</th>
        <th style="width: 18%;">项目部</th>
      </tr>
      <tr>
        <th>职责</th>
        <th>核查</th>
        <th>录入</th>
        <th>确认</th>
        <th>确认</th>
        <th>作成</th>
      </tr>
      <tr>
        <th>签章</th>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
        <td></td>
      </tr>
    </table>
  </div>
</template>

<script>
import { listG, getG, delG, addG, updateG, disableG  } from "@/api/bid/g";
import { getToken } from "@/utils/auth";
import { downBlobFile } from "@/utils/ruoyi";
import axios from 'axios';

export default {
  name: "G",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 实施预算-投标-实施-g表格数据
      gList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        contNo: null,
        name: null,
        busType: 1
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      // 用户导入参数
      upload: {
          // 是否显示弹出层（用户导入）
          open: false,
          // 弹出层标题（用户导入）
          title: "",
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的客户数据
          updateSupport: 0,
          // 设置上传的请求头部
          headers: { Authorization: "Bearer " + getToken() },
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + "/bid/g/importData"
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询实施预算-投标-实施-g列表 */
    getList() {
      this.loading = true;
      listG(this.queryParams).then(response => {
        this.gList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        createId: null,
        createTime: null,
        modifyId: null,
        modifyTime: null,
        status: null,
        isDel: null,
        createName: null,
        contNo: null,
        gCode: null,
        name: null,
        aNum: null,
        aUnit: null,
        bNum: null,
        bUnit: null,
        cNum: null,
        cUnit: null,
        abc: null,
        amount: null,
        tax: null,
        inTaxAmount: null,
        busType: 1
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      getG(id).then(response => {
        this.open = true;
        this.title = "添加实施预算-投标-实施-g";
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getG(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改实施预算-投标-实施-g";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateG(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addG(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除实施预算-投标-实施-g编号为"' + ids + '"的数据项？').then(function() {
        return delG(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('bid/g/export', {
        ...this.queryParams
      }, `实施预算-投标-实施-g_${new Date().getTime()}.xlsx`)
    },
    /** 导入按钮操作 */
    handleImport() {
        this.upload.title = "客户导入";
        this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
        this.download('erp/customer/importTemplate', {
        }, `实施预算-投标-实施-g_template_${new Date().getTime()}.xlsx`)
    },
    importData(file) {
        const loading = this.$loading({
            lock: true,
            text: '数据导入中...',
            spinner: 'el-icon-loading',
            background: 'rgba(0, 0, 0, 0.7)'
        });
        let formData = new FormData();
        formData.append('file', file.file);
        return axios.post(this.upload.url + '?updateSupport=' + this.upload.updateSupport, formData, {
            headers: this.upload.headers,
            responseType: 'blob'
        }).then(res => {
            loading.close()
            this.handleFileSuccess(res,file);
        }).catch(err => {
            loading.close()
        })
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
        this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
        this.upload.open = false;
        this.upload.isUploading = false;
        this.$refs.upload.clearFiles();
        if(res.data.type === 'application/json') {
            let reader = new FileReader()
            reader.readAsText(res.data);
            reader.onloadend= ()=> {
                let rsp = JSON.parse(reader.result);
                if(rsp.code == 200){
                    this.$modal.msgSuccess(rsp.msg);
                    this.getList();
                } else {
                    this.$modal.msgError(rsp.msg);
                }
            }
        } else {
            this.$modal.msgError("导入错误,请查看回执文件");
            let fileName = file.file.name;
            if (fileName.lastIndexOf(".xls") == fileName.length - 4 ){
                fileName =  fileName.substring(0, fileName.lastIndexOf(".xls"))
            } else if(fileName.lastIndexOf(".xlsx") == fileName.length - 5) {
                fileName =  fileName.substring(0, fileName.lastIndexOf(".xlsx"))
            }
            downBlobFile(downBlobFile(res.data,fileName+"Back.xlsx"));
        }
    },
    // 提交上传文件
    submitFileForm() {
        this.$refs.upload.submit();
    }
  }
};
</script>
<style lang="scss" scoped>
table{
  width: 100%;
  border-collapse: collapse;
  th, td{
    border: 1px solid #dfe6ec;
    color: #515a6e;
    padding: 5px;
    font-size: 14px;
  }
  th{
    background: #f8f8f9;
  }
}
</style>
